<template>
  <div>
    
    <el-upload class="avatar-uploader" action="#" :show-file-list="false" :on-change="changeFile">
        <img v-if="imgUrl" :src="imgUrl" class="avatar" />
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
  </div>
</template>

<script>
export default {
    data(){
        return {
            imgUrl:""
        }
    },
  methods: {
    changeFile(e) {
      let file = e.raw;

      //根据文件生成一个图片地址
      this.imgUrl = URL.createObjectURL(file);

      //给form.img
     this.$emit("sendFile",file)
    },
  },
};
</script>

<style scoped>
 .avatar-uploader /deep/.el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>